function dateSeparator() {
	let userAgent = navigator.userAgent; //取得浏览器的userAgent字符串
	let isSafari = userAgent.indexOf("Safari") >= 0 && userAgent.indexOf("Chrome") == -1; //判断是否Safari浏览器
	return isSafari ? '/' : '-';
}

function formatNumber(formatValue) {
	if (formatValue < 10) {
		formatValue = '0' + formatValue
	}
	return formatValue
}

function formatTime(date) {
	let year = date.getFullYear()
	let month = date.getMonth() + 1
	let day = date.getDate()
	let hour = date.getHours()
	let minute = date.getMinutes()
	let second = date.getSeconds()
	return [year, month, day].map(formatNumber).join(dateSeparator()) + ' ' + [hour, minute, second].map(formatNumber).join(':')
}

function formatTimeUpdate(date) {
	let year = date.getFullYear()
	let month = date.getMonth() + 1
	let day = date.getDate()
	let hour = date.getHours()
	let minute = date.getMinutes()
	let second = date.getSeconds()
	return [year, month, day].map(formatNumber).join(dateSeparator()) + [hour, minute, second].map(formatNumber).join(':')
}

function formatDate(date) {
	let year = date.getFullYear()
	let month = date.getMonth() + 1
	let day = date.getDate()
	return [year, month, day].map(formatNumber).join(dateSeparator())
}

function formatFriendDate(date) {
	let year = date.getFullYear()
	let month = date.getMonth() + 1
	let day = date.getDate()
	let date1 = new Date()
	let currentyear = date1.getFullYear()
	let currentmonth = date1.getMonth() + 1
	let currentday = date1.getDate()
	if (currentday == day && currentmonth == month && currentyear == year) {
		return '今天'
	} else {
		return [year, month, day].map(formatNumber).join(dateSeparator())
	}
}

function formatTimeStyle(date) {
	let year = date.getFullYear()
	let month = date.getMonth() + 1
	let day = date.getDate()
	let hour = date.getHours()
	let minute = date.getMinutes()
	let second = date.getSeconds()
	return year + '年' + month + '月' + day + '日 ' + [hour, minute].map(formatNumber).join(':')
}

function formatHourTime(date) {
	let hour = date.getHours()
	let minute = date.getMinutes()
	return [hour, minute].map(formatNumber).join(':')
}

function formatYearMonth(date) {
	let year = date.getFullYear()
	let month = date.getMonth() + 1
	return [year, month].map(formatNumber).join(dateSeparator())
}

//计算岁数
function formatYear(date) {
	let year = date.getFullYear()
	let date1 = new Date()
	let currentyear = date1.getFullYear()
	return currentyear - year
}

export default {
	dateSeparator,
	formatTime,
	formatDate,
	formatTimeUpdate,
	formatHourTime,
	formatFriendDate,
	formatYear,
	formatTimeStyle,
	formatYearMonth,
}
